package com.soccertgc.core.cards
{
	import com.soccertgc.core.DispatcherDataObject;
	import com.soccertgc.logging.Logger;
	import com.soccertgc.core.TargetType;

	public class CardTargetInput extends DispatcherDataObject
	{
		
		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------
		
		// JSON data properties definition
		protected static const 			JSON_PROPERTY_TYPE:String			= "type";
		protected static const 			JSON_PROPERTY_VALID:String			= "valid";
		
		
		// Default none input type
		
		public static const				NONE:CardTargetInput 				= CardTargetInput.getNoneTargetInput();
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		protected var _type:TargetType;
		protected var _parameter:Object;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTOR
		// -------------------------------------------------------------------------------
		
		public function CardTargetInput(data:Object = null)
		{
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------
		
		public function get type():TargetType
		{
			return _type;
		}
		
		public function set type(value:TargetType):void
		{
			_type = value;
		}
		
		public function get parameter():Object
		{
			return _parameter;
		}
		
		public function set parameter(value:Object):void
		{
			_parameter = value;
		}
		
		// -------------------------------------------------------------------------------
		// PRIVATE METHODS
		// -------------------------------------------------------------------------------
		
		protected function setParameter(param:Object):void
		{
			Logger.notImplemented("CardTargetInput", "setParameter");
		}
		
		// DataObject implementation
		
		override protected function validate(data:Object):void
		{
			if (!data.hasOwnProperty(JSON_PROPERTY_TYPE))	throwLoadMissingPropError(JSON_PROPERTY_TYPE);
			if (!data.hasOwnProperty(JSON_PROPERTY_VALID))	throwLoadMissingPropError(JSON_PROPERTY_VALID);
		}
		
		override protected function fill(data:Object):void
		{
			// Input Type
			_type = TargetType.getByDescription(data[JSON_PROPERTY_TYPE]);
			// Parameter
			setParameter(data[JSON_PROPERTY_VALID]);
		}
		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		override public function clear():void
		{
			// Clear data
			_parameter = null;
		}
		
		// -------------------------------------------------------------------------------
		// STATIC METHODS
		// -------------------------------------------------------------------------------
		
		/**
		 * Returns the NONE target 
		 * @return 
		 */		
		private static function getNoneTargetInput():CardTargetInput
		{
			var targetInput:CardTargetInput = new CardTargetInput();
			targetInput.type = TargetType.NONE;
			return targetInput;
		}
		
	}
}